import { t } from '@/locales';
import { createMemoryHistory } from 'vue-router';
import { isMicro } from '@micro/helper';
/**
 * 基础路由
 * 如果有业务需要，可以自行调整
 * 固定路由：Home(/),Login(/login)
 */
const routes = [
  {
    path: '/',
    name: 'Home',
    text: t('登录成功'),
    component: () => import('@/views/success/index.vue'),
  },
  {
    path: '/login',
    name: 'Login',
    text: t('登录'),
    component: () => import('@/views/login/index.vue'),
  },
];
export default routes;

/**
 * 自定义路由History
 * @returns History
 */
export function createRouterHistory() {
  return createMemoryHistory();
}

/**
 * 自定义路由守卫
 */
export function createRouterGuard(router) {
  // 微应用环境下，不跳转Home
  router.beforeEach((to, from, next) => {
    if (to.name === 'Home') {
      if (isMicro()) {
        next({ name: 'Login' });
      } else {
        next();
      }
      return;
    }
    next();
  });
}
